package com.spic.business.registrationform.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.business.registrationform.domain.ArchiveStaffJobholderRecords;
import com.spic.business.registrationform.service.IArchiveStaffJobholderRecordsService;

/**
 * 从业人员安全培训、考核记录Controller
 * 
 * @author spic
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/jobholder/records")
public class ArchiveStaffJobholderRecordsController extends BaseController
{
    @Autowired
    private IArchiveStaffJobholderRecordsService archiveStaffJobholderRecordsService;

    /**
     * 查询从业人员安全培训、考核记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ArchiveStaffJobholderRecords archiveStaffJobholderRecords)
    {
        startPage();
        List<ArchiveStaffJobholderRecords> list = archiveStaffJobholderRecordsService.selectArchiveStaffJobholderRecordsList(archiveStaffJobholderRecords);
        return getDataTable(list);
    }

    /**
     * 导出从业人员安全培训、考核记录列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveStaffJobholderRecords archiveStaffJobholderRecords) throws IOException {
        List<ArchiveStaffJobholderRecords> list = archiveStaffJobholderRecordsService.selectArchiveStaffJobholderRecordsList(archiveStaffJobholderRecords);
        ExcelUtil<ArchiveStaffJobholderRecords> util = new ExcelUtil<ArchiveStaffJobholderRecords>(ArchiveStaffJobholderRecords.class);
        util.exportExcel(response, list, "从业人员安全培训、考核记录数据");
    }

    /**
     * 获取从业人员安全培训、考核记录详细信息
     */
    @GetMapping(value = "/{studyId}")
    public AjaxResult getInfo(@PathVariable("studyId") Long studyId)
    {
        return AjaxResult.success(archiveStaffJobholderRecordsService.selectArchiveStaffJobholderRecordsByStudyId(studyId));
    }

    /**
     * 新增从业人员安全培训、考核记录
     */
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveStaffJobholderRecords archiveStaffJobholderRecords)
    {
        return toAjax(archiveStaffJobholderRecordsService.insertArchiveStaffJobholderRecords(archiveStaffJobholderRecords));
    }

    /**
     * 修改从业人员安全培训、考核记录
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveStaffJobholderRecords archiveStaffJobholderRecords)
    {
        return toAjax(archiveStaffJobholderRecordsService.updateArchiveStaffJobholderRecords(archiveStaffJobholderRecords));
    }

    /**
     * 删除从业人员安全培训、考核记录
     */
	@DeleteMapping("/{studyIds}")
    public AjaxResult remove(@PathVariable Long[] studyIds)
    {
        return toAjax(archiveStaffJobholderRecordsService.deleteArchiveStaffJobholderRecordsByStudyIds(studyIds));
    }
}
